﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using RoverStudio.Common.WorldModel;

namespace RoverStudio.MapDisplay.WM2D
{
    public partial class GeneralMPUC : UserControl, MapPlugin
    {
        private WorldModel worldModel;
        private MapDisplay2DControl mapDisplay;

        public GeneralMPUC()
        {
            InitializeComponent();

            
        }

        #region MapPlugin Members

        public WorldModel WorldModel
        {
            get { return worldModel; }
            set { 
                worldModel = value;
                SetZoom(50);
            }
        }


        public MapDisplay2DControl MapDisplay
        {
            get { return mapDisplay; }
            set { mapDisplay = value; }
        }

        public void HandleMapInteraction(object sender, MapUserInteractionEventArgs muie)
        {
            switch (muie.type)
            {
                case EventType.MouseBtnLeft:
                    mapDisplay.MoveOrigin(muie.eventPlaceOnScreen);
                    break;
                case EventType.MouseBtnRight:
                    break;
                case EventType.MouseMovement:
                    lblMousePosition.Text = string.Format("Mouse position: ({2},{3}) ({0},{1})",
                        muie.eventPlaceInWorld.X,
                        muie.eventPlaceInWorld.Y,
                        muie.eventPlaceOnScreen.X,
                        muie.eventPlaceOnScreen.Y);
                    break;

            }

        }

        public string Description
        {
            get { return string.Format("General control"); }
        }
 

        #endregion


        private void tbZoom_Scroll(object sender, EventArgs e)
        {
            SetZoom(tbZoom.Value);
        }

        public void SetZoom(int trackbarValue)
        {
            if (mapDisplay == null)
                return;
            double zoom = System.Math.Pow(2.0, ((double)trackbarValue) / 10.0);
            mapDisplay.Scale = zoom;
            lblZoom.Text = string.Format("Zoom: {0:f}", zoom);
            mapDisplay.Invalidate();
        }

    }
}
